---
title: Spec - howl.ui.CommandLine
tags: spec
---
<div class="spec-group spec-group-1">

<h1 id="howl.ui.commandline">howl.ui.CommandLine</h1>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">command_line</span><span class="p">,</span><span class="w"> </span><span class="n">run_as_handler</span><span class="w">

</span><span class="n">run_in_coroutine</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">wrapped</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">coroutine.wrap</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">f</span><span class="o">!</span><span class="w">
  </span><span class="k">return</span><span class="w"> </span><span class="n">wrapped</span><span class="o">!</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Window</span><span class="o">!</span><span class="w">
  </span><span class="n">command_line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">command_line</span><span class="w">
  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
      </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'within-activity'</span><span class="w">
      </span><span class="ss">handler:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">f</span><span class="o">!</span><span class="w">

</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">ok</span><span class="p">,</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">command_line</span><span class="o">\</span><span class="n">abort_all</span><span class="o">!</span><span class="w">
  </span><span class="k">if</span><span class="w"> </span><span class="ow">not</span><span class="w"> </span><span class="n">ok</span><span class="w">
    </span><span class="nb">print</span><span class="w"> </span><span class="n">result</span><span class="w">
  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
  </span><span class="n">command_line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>

<div class="spec-group spec-group-2">

<h2 id="command_line">command_line</h2>
<div class="spec-group spec-group-3">

<h3 id="\\run(activity_spec)">\\run(activity_spec)</h3>

<h4 id="errors-if-handler-or-factory-field-not-in-spec">errors if handler or factory field not in spec</h4>

<pre class="highlight moonscript"><code><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'requires "name" and one of "handler" or "factory" fields'</span><span class="p">,</span><span class="w"> </span><span class="n">f</span></code></pre>

<div class="spec-group spec-group-4">

<h4 id="for-activity-with-handler">for activity with handler</h4>

<h4 id="calls-activity-handler">calls activity handler</h4>

<pre class="highlight moonscript"><code><span class="n">handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-activity'</span><span class="w">
  </span><span class="ss">handler:</span><span class="w"> </span><span class="n">handler</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="w"> </span><span class="mi">1</span></code></pre>


<h4 id="passes-any-extra-args-to-handler">passes any extra args to handler</h4>

<pre class="highlight moonscript"><code><span class="n">handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">aspec</span><span class="w"> </span><span class="o">=</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-activity'</span><span class="w">
  </span><span class="ss">handler:</span><span class="w"> </span><span class="n">handler</span><span class="w">
</span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w"> </span><span class="n">aspec</span><span class="p">,</span><span class="w"> </span><span class="s1">'a1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a3'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'a1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a3'</span></code></pre>


<h4 id="returns-result-of-handler">returns result of handler</h4>

<pre class="highlight moonscript"><code><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-activity'</span><span class="w">
  </span><span class="ss">handler:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="s1">'r1'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'r1'</span><span class="p">,</span><span class="w"> </span><span class="n">result</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h4 id="for-activity-with-factory">for activity with factory</h4>

<h4 id="instantiates-facory,-calls-run-method">instantiates facory, calls run method</h4>

<pre class="highlight moonscript"><code><span class="n">handler</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">run_in_coroutine</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
    </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-factory'</span><span class="w">
    </span><span class="ss">factory:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
      </span><span class="ss">run:</span><span class="w"> </span><span class="n">handler</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="w"> </span><span class="mi">1</span></code></pre>


<h4 id="passes-instantiated-object,-finish-function,-extra-args-to-run">passes instantiated object, finish function, extra args to run</h4>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">args</span><span class="w">
</span><span class="n">obj</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">run:</span><span class="w"> </span><span class="p">(</span><span class="o">...</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="o">...</span><span class="p">}</span><span class="w">

</span><span class="n">aspec</span><span class="w"> </span><span class="o">=</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-factory'</span><span class="w">
  </span><span class="ss">factory:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">obj</span><span class="w">
</span><span class="n">run_in_coroutine</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w"> </span><span class="n">aspec</span><span class="p">,</span><span class="w"> </span><span class="s1">'a1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a2'</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">obj</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'function'</span><span class="p">,</span><span class="w"> </span><span class="nb">type</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'a1'</span><span class="p">,</span><span class="w"> </span><span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'a2'</span><span class="p">,</span><span class="w"> </span><span class="n">args</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span></code></pre>


<h4 id="returns-result-passed-in-finish-function">returns result passed in finish function</h4>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">result</span><span class="w">
</span><span class="n">run_in_coroutine</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
    </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-factory'</span><span class="w">
    </span><span class="ss">factory:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
      </span><span class="ss">run:</span><span class="w"> </span><span class="p">(</span><span class="n">finish</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">finish</span><span class="p">(</span><span class="s1">'r2'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'r2'</span><span class="p">,</span><span class="w"> </span><span class="n">result</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="\\run_after_finish(f)">\\run_after_finish(f)</h3>

<h4 id="calls-f!-immediately-after-the-current-activity-stack-exits">calls f! immediately after the current activity stack exits</h4>

<pre class="highlight moonscript"><code><span class="n">nextf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-activity'</span><span class="w">
  </span><span class="ss">handler:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="n">command_line</span><span class="o">\</span><span class="n">run_after_finish</span><span class="w"> </span><span class="n">nextf</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">nextf</span><span class="p">).</span><span class="n">was_called</span><span class="w"> </span><span class="mi">1</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="\\switch_to(new_command)">\\switch_to(new_command)</h3>

<h4 id="cancels-current-command-and-runs-new-command,-preserving-text">cancels current command and runs new command, preserving text</h4>

<pre class="highlight moonscript"><code><span class="n">command_run</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">command</span><span class="p">.</span><span class="n">run</span><span class="w">
</span><span class="n">timer_asap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">timer</span><span class="p">.</span><span class="n">asap</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">timer</span><span class="p">.</span><span class="n">asap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">f</span><span class="o">!</span><span class="w">
</span><span class="n">new_run</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">command</span><span class="p">.</span><span class="n">run</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">new_run</span><span class="w">
</span><span class="n">command_line</span><span class="o">\</span><span class="n">run</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'run-activity'</span><span class="w">
  </span><span class="ss">handler:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello arg'</span><span class="w">
    </span><span class="n">command_line</span><span class="o">\</span><span class="n">switch_to</span><span class="w"> </span><span class="s1">'new-command'</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">command</span><span class="p">.</span><span class="n">run</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">command_run</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">timer</span><span class="p">.</span><span class="n">asap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">timer_asap</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">new_run</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'new-command hello arg'</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id=".text">.text</h3>

<h4 id="cannot-be-set-when-no-running-activity">cannot be set when no running activity</h4>

<pre class="highlight moonscript"><code><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'no running activity'</span><span class="p">,</span><span class="w"> </span><span class="n">f</span></code></pre>


<h4 id="returns-nil-when-no-running-activity">returns nil when no running activity</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="updates-the-text-displayed-in-the-command_widget">updates the text displayed in the command_widget</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'bye'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'bye'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="returns-the-text-previously-set">returns the text previously set</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hi'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hi'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id=".prompt">.prompt</h3>

<h4 id="does-not-work-when-no-running-activity">does not work when no running activity</h4>

<pre class="highlight moonscript"><code><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'no running activity'</span><span class="p">,</span><span class="w"> </span><span class="n">f</span></code></pre>


<h4 id="updates-the-prompt-displayed-in-the-command_widget">updates the prompt displayed in the command_widget</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'bye'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'bye'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="returns-the-prompt-previously-set">returns the prompt previously set</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'set'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'set'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="title">title</h3>

<h4 id="is-hidden-by-default">is hidden by default</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">header</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!</span><span class="p">.</span><span class="n">visible</span></code></pre>


<h4 id="is-shown-and-updated-by-setting-.title">is shown and updated by setting .title</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Nice Title'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Nice Title'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">indic_title</span><span class="p">.</span><span class="n">label</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">header</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!</span><span class="p">.</span><span class="n">visible</span></code></pre>


<h4 id="is-hidden-by-setting-title-to-empty-string">is hidden by setting title to empty string</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Nice Title'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">header</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!</span><span class="p">.</span><span class="n">visible</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">header</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!</span><span class="p">.</span><span class="n">visible</span></code></pre>


<h4 id="is-restored-to-the-one-set-by-the-current-interaction">is restored to the one set by the current interaction</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Title 0'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Title 0'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">indic_title</span><span class="p">.</span><span class="n">label</span><span class="w">

  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Title 1'</span><span class="w">
    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Title 1'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">indic_title</span><span class="p">.</span><span class="n">label</span><span class="w">

  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Title 0'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">indic_title</span><span class="p">.</span><span class="n">label</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="when-using-both-.prompt-and-.text">when using both .prompt and .text</h3>

<h4 id="the-prompt-is-displayed-before-the-text">the prompt is displayed before the text</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'prómpt:'</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'téxt'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'prómpt:téxt'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="preserves-text-when-updating-prompt">preserves text when updating prompt</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'héllo:'</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'téxt'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'héllo:téxt'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hóla:'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hóla:téxt'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="preserves-prompt-when-updating-téxt-">preserves prompt when updating téxt </h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'héllo:'</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'téxt '</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'héllo:téxt '</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hóla'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'héllo:hóla'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(clear())">(clear())</h3>

<h4 id="clears-the-text-only,-leaving-prompt-intact">clears the text only, leaving prompt intact</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'héllo:'</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'téxt'</span><span class="w">
  </span><span class="n">command_line</span><span class="o">\</span><span class="n">clear</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'héllo:'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="when-using-nested-interactions">when using nested interactions</h3>

<h4 id="each-interaction-has-independent-prompt-and-text">each interaction has independent prompt and text</h4>

<pre class="highlight moonscript"><code><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'outer:'</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'0'</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'outer:0'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">

  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'inner:'</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1'</span><span class="w">
    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'outer:0inner:1'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'later:'</span><span class="w">
    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'outer:0later:1'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">

  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'outer:0'</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id=".stack_depth-returns-number-of-running-activities">.stack_depth returns number of running activities</h4>

<pre class="highlight moonscript"><code><span class="n">depths</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
</span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
    </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
      </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
  </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
</span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">depths</span></code></pre>


<h4 id="\\abort_all!-cancels-all-running-activities">\\abort_all! cancels all running activities</h4>

<pre class="highlight moonscript"><code><span class="n">depths</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
</span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
    </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
      </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
      </span><span class="n">command_line</span><span class="o">\</span><span class="n">abort_all</span><span class="o">!</span><span class="w">
      </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">depths</span></code></pre>


<h4 id="finishing-any-activity-aborts-all-nested-activities">finishing any activity aborts all nested activities</h4>

<pre class="highlight moonscript"><code><span class="n">depths</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
</span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">dispatch</span><span class="p">.</span><span class="n">launch</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
    </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dispatch</span><span class="p">.</span><span class="n">park</span><span class="w"> </span><span class="s1">'command_line_test'</span><span class="w">
    </span><span class="n">dispatch</span><span class="p">.</span><span class="n">launch</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
      </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
          </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">
          </span><span class="n">dispatch</span><span class="p">.</span><span class="n">resume</span><span class="w"> </span><span class="n">p</span><span class="w">

    </span><span class="n">dispatch</span><span class="p">.</span><span class="n">wait</span><span class="w"> </span><span class="n">p</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">depths</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">stack_depth</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="n">depths</span></code></pre>


<h4 id="\\clear_all!-clears-the-entire-command-line-and-restores-on-exit">\\clear_all! clears the entire command line and restores on exit</h4>

<pre class="highlight moonscript"><code><span class="n">texts</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'outér:'</span><span class="w">
  </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'0'</span><span class="w">
  </span><span class="n">run_as_handler</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">texts</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
    </span><span class="n">command_line</span><span class="o">\</span><span class="n">clear_all</span><span class="o">!</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">texts</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'innér:'</span><span class="w">
    </span><span class="n">command_line</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1'</span><span class="w">
    </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">texts</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
  </span><span class="nb">table.insert</span><span class="w"> </span><span class="n">texts</span><span class="p">,</span><span class="w"> </span><span class="n">command_line</span><span class="p">.</span><span class="n">command_widget</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'outér:0'</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="s1">'innér:1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'outér:0'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">texts</span></code></pre>

</div>
</div>
</div>
